﻿<UserControl x:Class="ShaderPad.TVComboControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="20" MinWidth="50" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignWidth="162" d:DesignHeight="21.96">
    <Grid >
        <ToggleButton x:Name="Part_ToggleButton" Checked="Part_ToggleButton_Checked" Unchecked="Part_ToggleButton_Unchecked" 
                      Content="{Binding ElementName=Part_ComboTextBox, Path=Text}"/>
        <DockPanel >
            <TextBlock DockPanel.Dock="Right" Margin="4" FontFamily="Webdings" Text="6" MouseLeftButtonDown="TextBlock_MouseLeftButtonDown"/>
            <Border BorderThickness="0,0,1,0">
            	<Border.BorderBrush>
            		<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
            			<GradientStop Color="#FF8A8A8A" Offset="0.506"/>
            			<GradientStop Color="#00000000" Offset="0.798"/>
            			<GradientStop Color="#00000000" Offset="0.156"/>
            		</LinearGradientBrush>
            	</Border.BorderBrush>
            	<Grid>
            		<TextBox x:Name="Part_ComboTextBox" HorizontalAlignment="Stretch" Margin="2,2,2,2" VerticalAlignment="Stretch" Visibility="Collapsed" Text="" TextWrapping="Wrap"/>
            	</Grid>
            </Border>
        </DockPanel>
        <Popup x:Name="Part_Dropdown" PlacementTarget="{Binding ElementName=Part_ToggleButton}"
               IsOpen="{Binding ElementName=Part_ToggleButton,Path=IsChecked}"
               Width="{Binding ElementName=Part_ToggleButton, Path=ActualWidth}" StaysOpen="True" PopupAnimation="Slide">
            <Popup.Effect>
                <DropShadowEffect/>
            </Popup.Effect>
            <TreeView x:Name="Part_TreeView" Height="250" SelectedItemChanged="Part_TreeView_SelectedItemChanged">
                <TreeView.ItemTemplate>
                    <HierarchicalDataTemplate ItemsSource="{Binding Children}">
                        <StackPanel Orientation="Horizontal">
                            <Viewbox Width="60" Height="20" Stretch="Uniform">
                                <Border Width="{Binding Path=Element.ActualWidth}"
                                        Height="{Binding Path=Element.ActualHeight}">
                                    <Border.Background>
                                        <VisualBrush Visual="{Binding Element}"/>
                                    </Border.Background>
                                </Border>
                            </Viewbox>
                            <TextBlock Text="{Binding Name}"/>
                            <StackPanel.ToolTip>
                                <Border Width="{Binding Path=Element.ActualWidth}"
                                        Height="{Binding Path=Element.ActualHeight}">
                                    <Border.Background>
                                        <VisualBrush Visual="{Binding Element}"/>                                        
                                    </Border.Background>
                                </Border>
                            </StackPanel.ToolTip>
                        </StackPanel>
                    </HierarchicalDataTemplate>
                </TreeView.ItemTemplate>
                <TreeView.ItemContainerStyle>
                    <Style TargetType="{x:Type TreeViewItem}">
                        <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
                        <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
                        <Setter Property="FontWeight" Value="Normal" />
                        <Style.Triggers>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter Property="FontWeight" Value="Bold" />
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </TreeView.ItemContainerStyle>
            </TreeView>
        </Popup>
    </Grid>
</UserControl>
